import { ref } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
import { getJobDataApi } from "@/api/job"
export const useJobStore = defineStore(
  "job",
  () => {
    const jobListStore = ref<string[]>([])
    /** 设置职位列表 */
    const setJobList = (value: string[]) => {
      jobListStore.value = value
    }
    const getJobFn = async () => {
      await getJobDataApi({
        page: 1,
        size: 100
      }).then((res: any) => {
        setJobList(res.data)
      })
    }
    /**actions */
    // {
    //   //职位持久化
    //   getJobDataApi({
    //     page: 1,
    //     size: 100
    //   }).then((res: any) => {
    //     setJobList(res.data)
    //   })
    // }
    /**actions END */
    return {
      jobListStore,
      setJobList,
      getJobFn
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
          // paths: ["jobListStore", "authListStore"] //指定要长久化的字段
        }
      ]
    }
  }
)
/** 在 setup 外使用 */
export function useJobStoreHook() {
  return useJobStore(store)
}
